package com.peng.leetcode.tree;

/**
 * MaxDepth1
 * 104. 二叉树的最大深度
 * https://leetcode.cn/problems/maximum-depth-of-binary-tree/
 * <p>
 * Created on 2022/11/29
 *
 * @author lupeng
 */
public class MaxDepth1 {
    int ans = 0;
    public int maxDepth(TreeNode root) {
        if (root == null) {
            return 0;
        }
        dfs(root, 0);
        return ans;
    }

    public void dfs(TreeNode n, int d) {
        if (n == null) {
            ans = Math.max(ans, d);
            return;
        }
        dfs(n.left, d + 1);
        dfs(n.right, d + 1);
    }

}
